package com.cy.util;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一JSON格式返回类
 * @author wxhn1
 * @param <T>
 */
@Data
@NoArgsConstructor
public class R<T> {
    // 自定义状态码、消息内容、数据
    private Integer code;
    private String msg;
    private T data;

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> R<T> ok(){
        return new R<>(200,"success");
    }

    public static <T> R<T> ok(Integer code, String msg, T data) {
        return new R<>(code, msg, data);
    }
    public static <T> R<T> ok(String msg, T data) {
        return new R<>(200, msg, data);
    }
    public static <T> R<T> ok(int code,String msg){
        return new R<>(code,msg);
    }
    public static <T> R<T> ok(String msg){
        return new R<>(200,msg);
    }
    public static <T> R<T> ok(T data){
        return new R<>(200,"success",data);
    }

    public static <T> R<T> fail(){
        return new R<>(500,"fail");
    }
    public static <T> R<T> fail(int code,String msg){
        return new R<>(code,msg);
    }
    public static <T> R<T> fail(String msg){
        return new R<>(500,msg);
    }
}
